from py_code.SingletonType import SingletonType
from py_code.driver.Driver import Driver
import cv2


class Camera(Driver, metaclass=SingletonType):
    """
    摄像头驱动
    """
    cap: cv2.VideoCapture

    def open(self):
        self.cap = cv2.VideoCapture(0)

    def close(self):
        self.cap.release()

    def read(self):
        self.openDriverIfClosed()
        return self.cap.read()
